package MediaOnline.WebService;

import java.util.ArrayList;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import MediaOnline.Data.ThongTinDienVien;
import MediaOnline.GUI.actActorInfo;
import MediaOnline.General.paramConst;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ArrayAdapter;

public class GetActorByID {
/** Called when the activity is first created. */
    
	private static final String Soap_MethodName = "AndroidGetActorByID";
	private static final String Soap_Action = paramConst.Webservice_NameSpace+Soap_MethodName;
	private static final String Soap_NameSpace = paramConst.Webservice_NameSpace;
	private static final String Soap_URL = paramConst.Webservice_Url+"ActorService.asmx?op="+Soap_MethodName;
	public Context mContext;
	public ArrayList<String> arrUser;
	public SoapObject request, request2;
	public SoapSerializationEnvelope Soap_Evelope;
	public ArrayAdapter<String> adpUser;
	
	public boolean isOnline=false;
	//ProgressDialog progress; 
		public GetActorByID(Context ctx){
			mContext = ctx;
			request = new SoapObject(Soap_NameSpace, Soap_MethodName);
			Soap_Evelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
	        //Soap_Evelope.addMapping(Soap_NameSpace, "actViewAllUser", this.getClass());
	        Soap_Evelope.dotNet=true;
	        request.addProperty("ID",ThongTinDienVien.ID);
	        Soap_Evelope.setOutputSoapObject(request);
		}
		
		public void get(){
			getActorByID c = new getActorByID();
	      	c.execute();
        }

	class getActorByID extends AsyncTask<String, Void, String> {

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			//Start activity film info
			actActorInfo.UpdateInfo();
			//progress.dismiss();
			Log.d("Asynctask ::: ", "Post");			
		}

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
		}

		@Override
		protected void onProgressUpdate(Void... values) {
			// TODO Auto-generated method stub
			
		}


		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			Log.d("Asynctask ::: ", "Background");
	        HttpTransportSE androidHttpTransport = new HttpTransportSE(Soap_URL);
	        
	     	//CallService
	      	try{
	      		androidHttpTransport.call(Soap_Action, Soap_Evelope);
	            //Lay du lieu file xml
	      		SoapObject requestall=(SoapObject) Soap_Evelope.getResponse();
	      		Log.d("request all::::", requestall.toString());
	            //loc cac thong tin thua
	            request = (SoapObject) requestall.getProperty(0);
	            int i = request.getPropertyCount();
	            Log.d("So dong du lieu :::::::", ""+i+" dong");
	            int x=0;
	            //Lay thong tin chi tiet
		        request2=(SoapObject) request.getProperty(0);
		        ThongTinDienVien.Ten = request2.getProperty("Name").toString();
		        ThongTinDienVien.NgaySinh = request2.getProperty("Birthday").toString();
		        ThongTinDienVien.NoiSinh = request2.getProperty("Biography").toString();
		        ThongTinDienVien.VaiTro = request2.getProperty("Type").toString();
		        ThongTinDienVien.ImgUrl = request2.getProperty("ThumImage").toString();
		        //Test
		        Log.d("Ten dv ::: ", ThongTinDienVien.Ten);
		        Log.d("ngay sinh ::: ", ThongTinDienVien.NgaySinh);
		        Log.d("Noi sinh ::: ", ThongTinDienVien.NoiSinh);
		        Log.d("Vai tro::: ", ThongTinDienVien.VaiTro);
		        Log.d("imgURL ::: ", ThongTinDienVien.ImgUrl);
		        
		        
		        
		        //ThongTinDienVien.CacGiaiThuong = request2.getProperty("Name").toString();
		        //ThongTinDienVien.TieuSu = request2.getProperty("Name").toString();
		        
			}
			catch(Exception e){
				Log.d("Asynctask exception ::: ", e.toString());

			}
			return null;
		}
		
	}
}
